<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
    <link href="../../cron/font/font-awesome.min.css" rel="stylesheet">
    <link href="../../cron/cronGen.css" rel="stylesheet">
    <script src="../../cron/jquery-2.1.4.min.js"></script>
    <script src="../../cron/later.min.js"></script>
    <script src="../../cron/cronGen.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#cron").cronGen({
                direction: 'right'
            });
        });
    </script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" style="margin-left: 160px;">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <div class="form-group">
                <label class="col-md-2 control-label jobLabel">定时任务名称</label>
                <div class="col-md-10 jobDiv">
                    <input class="form-control" placeholder="job名" type="text" maxlength="60" name="jobName"
                           id="jobName" readonly="readonly">
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label jobLabel">cron表达式</label>
                <div class="col-md-10 form-inline jobDiv">
                    <input class="form-control" placeholder="cron表达式" type="text" name="cron" id="cron"
                           data-bv-notempty="true" data-bv-notempty-message="cron表达式 不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label jobLabel">定时任务描述</label>
                <div class="col-md-10 jobDiv">
                    <input class="form-control" placeholder="job描述" type="text" maxlength="100" name="description"
                           id="description">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label jobLabel">类名</label>
                <div class="col-md-10 form-inline jobDiv">
                    <select class="selectpicker show-tick form-control" data-live-search="true" name="springBeanName"
                            id="springBeanName" onchange="showMethods()"></select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label jobLabel">方法名<span style="color: red">（目前仅支持无参方法）</span></label>
                <div class="col-md-10 form-inline jobDiv">
                    <select class="form-control" name="methodName" id="methodName"
                            data-bv-notempty="true" data-bv-notempty-message="方法名 不能为空"></select>
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-10">
                        <button class="btn btn-primary" onclick="location.href='jobList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/bootstrap/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/job.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
    });

    initBeanNames();
    initData();

    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: '/jobs/' + id,
                async: false,
                success: function (data) {
                    $("#id").val(data.id);
                    $("#jobName").val(data.jobName);
                    $("#cron").val(data.cron);
                    $("#description").val(data.description);
                    //	$("#springBeanName").val(data.springBeanName);
                    $('.selectpicker').selectpicker('val', data.springBeanName);
                    showMethods();
                    $("#methodName").val(data.methodName);
                }
            });
        }
    }

    function update() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

        var formdata = $("#form").serializeObject();

        $.ajax({
            type: 'put',
            url: '/jobs',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "jobList.html";
                });
            }
        });
    }

</script>
</body>
</html>